<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="配货日期" prop="rq">
        <el-date-picker clearable
          v-model="queryParams.rq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择配货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="原单据号" prop="ydjh">
        <el-input
          v-model="queryParams.ydjh"
          placeholder="请输入原单据号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道代码" prop="qddm">
        <el-input
          v-model="queryParams.qddm"
          placeholder="请输入渠道代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道名称" prop="qdmc">
        <el-input
          v-model="queryParams.qdmc"
          placeholder="请输入渠道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域代码" prop="qydm">
        <el-input
          v-model="queryParams.qydm"
          placeholder="请输入区域代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域名称" prop="qymc">
        <el-input
          v-model="queryParams.qymc"
          placeholder="请输入区域名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工代码" prop="ygdm">
        <el-input
          v-model="queryParams.ygdm"
          placeholder="请输入员工代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工名称" prop="ygmc">
        <el-input
          v-model="queryParams.ygmc"
          placeholder="请输入员工名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否审核" prop="sh">
        <el-input
          v-model="queryParams.sh"
          placeholder="请输入是否审核"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否生成或导出" prop="jz">
        <el-input
          v-model="queryParams.jz"
          placeholder="请输入是否生成或导出"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否终止" prop="sp">
        <el-input
          v-model="queryParams.sp"
          placeholder="请输入是否终止"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域名称" prop="bz">
        <el-input
          v-model="queryParams.bz"
          placeholder="请输入区域名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新日期" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:sdphd:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:sdphd:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:sdphd:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:sdphd:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sdphdList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="单据ID" align="center" prop="id" />
      <el-table-column label="配货日期" align="center" prop="rq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原单据号" align="center" prop="ydjh" />
      <el-table-column label="渠道代码" align="center" prop="qddm" />
      <el-table-column label="渠道名称" align="center" prop="qdmc" />
      <el-table-column label="区域代码" align="center" prop="qydm" />
      <el-table-column label="区域名称" align="center" prop="qymc" />
      <el-table-column label="员工代码" align="center" prop="ygdm" />
      <el-table-column label="员工名称" align="center" prop="ygmc" />
      <el-table-column label="是否审核" align="center" prop="sh" />
      <el-table-column label="是否生成或导出" align="center" prop="jz" />
      <el-table-column label="是否终止" align="center" prop="sp" />
      <el-table-column label="区域名称" align="center" prop="bz" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建日期" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新日期" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:sdphd:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:sdphd:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改智能配货单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="配货日期" prop="rq">
          <el-date-picker clearable
            v-model="form.rq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择配货日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="原单据号" prop="ydjh">
          <el-input v-model="form.ydjh" placeholder="请输入原单据号" />
        </el-form-item>
        <el-form-item label="渠道代码" prop="qddm">
          <el-input v-model="form.qddm" placeholder="请输入渠道代码" />
        </el-form-item>
        <el-form-item label="渠道名称" prop="qdmc">
          <el-input v-model="form.qdmc" placeholder="请输入渠道名称" />
        </el-form-item>
        <el-form-item label="区域代码" prop="qydm">
          <el-input v-model="form.qydm" placeholder="请输入区域代码" />
        </el-form-item>
        <el-form-item label="区域名称" prop="qymc">
          <el-input v-model="form.qymc" placeholder="请输入区域名称" />
        </el-form-item>
        <el-form-item label="员工代码" prop="ygdm">
          <el-input v-model="form.ygdm" placeholder="请输入员工代码" />
        </el-form-item>
        <el-form-item label="员工名称" prop="ygmc">
          <el-input v-model="form.ygmc" placeholder="请输入员工名称" />
        </el-form-item>
        <el-form-item label="是否审核" prop="sh">
          <el-input v-model="form.sh" placeholder="请输入是否审核" />
        </el-form-item>
        <el-form-item label="是否生成或导出" prop="jz">
          <el-input v-model="form.jz" placeholder="请输入是否生成或导出" />
        </el-form-item>
        <el-form-item label="是否终止" prop="sp">
          <el-input v-model="form.sp" placeholder="请输入是否终止" />
        </el-form-item>
        <el-form-item label="区域名称" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入区域名称" />
        </el-form-item>
        <el-divider content-position="center">智能配货明细单信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddBxSdphdmx">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteBxSdphdmx">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="bxSdphdmxList" :row-class-name="rowBxSdphdmxIndex" @selection-change="handleBxSdphdmxSelectionChange" ref="bxSdphdmx">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="客户代码" prop="khdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khdm" placeholder="请输入客户代码" />
            </template>
          </el-table-column>
          <el-table-column label="客户名称" prop="khmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khmc" placeholder="请输入客户名称" />
            </template>
          </el-table-column>
          <el-table-column label="客户区域代码" prop="khQydm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khQydm" placeholder="请输入客户区域代码" />
            </template>
          </el-table-column>
          <el-table-column label="客户区域名称" prop="khQymc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khQymc" placeholder="请输入客户区域名称" />
            </template>
          </el-table-column>
          <el-table-column label="客户指定品牌代码" prop="khPpdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khPpdm" placeholder="请输入客户指定品牌代码" />
            </template>
          </el-table-column>
          <el-table-column label="客户指定品牌名称" prop="khPpmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khPpmc" placeholder="请输入客户指定品牌名称" />
            </template>
          </el-table-column>
          <el-table-column label="配货仓库代码" prop="ckdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ckdm" placeholder="请输入配货仓库代码" />
            </template>
          </el-table-column>
          <el-table-column label="配货仓库代码" prop="ckmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ckmc" placeholder="请输入配货仓库代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品代码" prop="spdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.spdm" placeholder="请输入商品代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品名称" prop="spmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.spmc" placeholder="请输入商品名称" />
            </template>
          </el-table-column>
          <el-table-column label="他白色代码" prop="gg1dm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.gg1dm" placeholder="请输入他白色代码" />
            </template>
          </el-table-column>
          <el-table-column label="暗色名称" prop="gg1mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.gg1mc" placeholder="请输入暗色名称" />
            </template>
          </el-table-column>
          <el-table-column label="尺码代码" prop="gg2dm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.gg2dm" placeholder="请输入尺码代码" />
            </template>
          </el-table-column>
          <el-table-column label="尺码名称" prop="gg2mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.gg2mc" placeholder="请输入尺码名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品年份" prop="nianfen" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.nianfen" placeholder="请输入商品年份" />
            </template>
          </el-table-column>
          <el-table-column label="大类代码" prop="dldm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.dldm" placeholder="请输入大类代码" />
            </template>
          </el-table-column>
          <el-table-column label="大类名称" prop="dlmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.dlmc" placeholder="请输入大类名称" />
            </template>
          </el-table-column>
          <el-table-column label="季节代码" prop="jjdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jjdm" placeholder="请输入季节代码" />
            </template>
          </el-table-column>
          <el-table-column label="季节名称" prop="jjmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jjmc" placeholder="请输入季节名称" />
            </template>
          </el-table-column>
          <el-table-column label="品牌代码" prop="ppdm" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ppdm" placeholder="请输入品牌代码" />
            </template>
          </el-table-column>
          <el-table-column label="品牌名称" prop="ppmc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ppmc" placeholder="请输入品牌名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性1代码" prop="fjsx1" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx1" placeholder="请输入商品属性1代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性1名称" prop="fjsx1mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx1mc" placeholder="请输入商品属性1名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性2代码" prop="fjsx2" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx2" placeholder="请输入商品属性2代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性2名称" prop="fjsx2mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx2mc" placeholder="请输入商品属性2名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性3代码" prop="fjsx3" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx3" placeholder="请输入商品属性3代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性3名称" prop="fjsx3mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx3mc" placeholder="请输入商品属性3名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性4代码" prop="fjsx4" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx4" placeholder="请输入商品属性4代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性4名称" prop="fjsx4mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx4mc" placeholder="请输入商品属性4名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性5代码" prop="fjsx5" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx5" placeholder="请输入商品属性5代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性5名称" prop="fjsx5mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx5mc" placeholder="请输入商品属性5名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性8代码" prop="fjsx6" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx6" placeholder="请输入商品属性8代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性8名称" prop="fjsx6mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx6mc" placeholder="请输入商品属性8名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性7代码" prop="fjsx7" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx7" placeholder="请输入商品属性7代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性7名称" prop="fjsx7mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx7mc" placeholder="请输入商品属性7名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性8代码" prop="fjsx8" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx8" placeholder="请输入商品属性8代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性8名称" prop="fjsx8mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx8mc" placeholder="请输入商品属性8名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性9代码" prop="fjsx9" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx9" placeholder="请输入商品属性9代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性9名称" prop="fjsx9mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx9mc" placeholder="请输入商品属性9名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性10代码" prop="fjsx10" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx10" placeholder="请输入商品属性10代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性10名称" prop="fjsx10mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx10mc" placeholder="请输入商品属性10名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性11代码" prop="fjsx11" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx11" placeholder="请输入商品属性11代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性11名称" prop="fjsx11mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx11mc" placeholder="请输入商品属性11名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性112代码" prop="fjsx12" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx12" placeholder="请输入商品属性112代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性12名称" prop="fjsx12mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx12mc" placeholder="请输入商品属性12名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性13代码" prop="fjsx13" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx13" placeholder="请输入商品属性13代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性13名称" prop="fjsx13mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx13mc" placeholder="请输入商品属性13名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性14代码" prop="fjsx14" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx14" placeholder="请输入商品属性14代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性14名称" prop="fjsx14mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx14mc" placeholder="请输入商品属性14名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性15代码" prop="fjsx15" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx15" placeholder="请输入商品属性15代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性15名称" prop="fjsx15mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx15mc" placeholder="请输入商品属性15名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性16代码" prop="fjsx16" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx16" placeholder="请输入商品属性16代码" />
            </template>
          </el-table-column>
          <el-table-column label="商品属性16名称" prop="fjsx16mc" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fjsx16mc" placeholder="请输入商品属性16名称" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSdphd, getSdphd, delSdphd, addSdphd, updateSdphd } from "@/api/system/sdphd";

export default {
  name: "Sdphd",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedBxSdphdmx: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 智能配货单表格数据
      sdphdList: [],
      // 智能配货明细单表格数据
      bxSdphdmxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rq: null,
        ydjh: null,
        qddm: null,
        qdmc: null,
        qydm: null,
        qymc: null,
        ygdm: null,
        ygmc: null,
        sh: null,
        jz: null,
        sp: null,
        bz: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rq: [
          { required: true, message: "配货日期不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询智能配货单列表 */
    getList() {
      this.loading = true;
      listSdphd(this.queryParams).then(response => {
        this.sdphdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rq: null,
        ydjh: null,
        qddm: null,
        qdmc: null,
        qydm: null,
        qymc: null,
        ygdm: null,
        ygmc: null,
        sh: null,
        jz: null,
        sp: null,
        bz: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.bxSdphdmxList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加智能配货单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSdphd(id).then(response => {
        this.form = response.data;
        this.bxSdphdmxList = response.data.bxSdphdmxList;
        this.open = true;
        this.title = "修改智能配货单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.bxSdphdmxList = this.bxSdphdmxList;
          if (this.form.id != null) {
            updateSdphd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSdphd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除智能配货单编号为"' + ids + '"的数据项？').then(function() {
        return delSdphd(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 智能配货明细单序号 */
    rowBxSdphdmxIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 智能配货明细单添加按钮操作 */
    handleAddBxSdphdmx() {
      let obj = {};
      obj.khdm = "";
      obj.khmc = "";
      obj.khQydm = "";
      obj.khQymc = "";
      obj.khPpdm = "";
      obj.khPpmc = "";
      obj.ckdm = "";
      obj.ckmc = "";
      obj.spdm = "";
      obj.spmc = "";
      obj.gg1dm = "";
      obj.gg1mc = "";
      obj.gg2dm = "";
      obj.gg2mc = "";
      obj.nianfen = "";
      obj.dldm = "";
      obj.dlmc = "";
      obj.jjdm = "";
      obj.jjmc = "";
      obj.ppdm = "";
      obj.ppmc = "";
      obj.fjsx1 = "";
      obj.fjsx1mc = "";
      obj.fjsx2 = "";
      obj.fjsx2mc = "";
      obj.fjsx3 = "";
      obj.fjsx3mc = "";
      obj.fjsx4 = "";
      obj.fjsx4mc = "";
      obj.fjsx5 = "";
      obj.fjsx5mc = "";
      obj.fjsx6 = "";
      obj.fjsx6mc = "";
      obj.fjsx7 = "";
      obj.fjsx7mc = "";
      obj.fjsx8 = "";
      obj.fjsx8mc = "";
      obj.fjsx9 = "";
      obj.fjsx9mc = "";
      obj.fjsx10 = "";
      obj.fjsx10mc = "";
      obj.fjsx11 = "";
      obj.fjsx11mc = "";
      obj.fjsx12 = "";
      obj.fjsx12mc = "";
      obj.fjsx13 = "";
      obj.fjsx13mc = "";
      obj.fjsx14 = "";
      obj.fjsx14mc = "";
      obj.fjsx15 = "";
      obj.fjsx15mc = "";
      obj.fjsx16 = "";
      obj.fjsx16mc = "";
      this.bxSdphdmxList.push(obj);
    },
    /** 智能配货明细单删除按钮操作 */
    handleDeleteBxSdphdmx() {
      if (this.checkedBxSdphdmx.length == 0) {
        this.$modal.msgError("请先选择要删除的智能配货明细单数据");
      } else {
        const bxSdphdmxList = this.bxSdphdmxList;
        const checkedBxSdphdmx = this.checkedBxSdphdmx;
        this.bxSdphdmxList = bxSdphdmxList.filter(function(item) {
          return checkedBxSdphdmx.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleBxSdphdmxSelectionChange(selection) {
      this.checkedBxSdphdmx = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/sdphd/export', {
        ...this.queryParams
      }, `sdphd_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
